#pragma once

#include<mysql/mysql.h>
#include<string>
#include<ctime>
using namespace std;

class Connection{
public:
    Connection();
    ~Connection();

    bool connect(string ip,unsigned short port,string user,string password,string dbname);
    bool update(string sql);
    MYSQL_RES* query(string sql);

    // 刷新连接的存活时间
    void refreshAliveTime(){_alivetime=clock();}
    // 获取连接的空闲时间
    clock_t getAliveTime(){return clock()-_alivetime;}

private:
    //表示一条和MYSQL的连接 
    MYSQL* _conn;   
    //记录进入空闲状态后(进入队列) 的起始存活时间
    clock_t _alivetime;
};